<html>
<head><meta charset="utf-8"><title>rust-project.json and the core and alloc crates · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html">rust-project.json and the core and alloc crates</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205187328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205187328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205187328">(Jul 28 2020 at 01:18)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="133169">@matklad</span> , I'm looking into adding better support for the <code>core</code> and <code>alloc</code> traits when analyzing a project that uses <code>rust-project.json</code>. <code>core</code> is especially tricky because its <code>extern crate core;</code> statement is added by <code>#![no_std]</code>.</p>
<p>We can solve this outside of RA by just including <code>core</code> and <code>alloc</code> as automatic dependencies in all roots, even if unused. Though it is adding unnecessary dependencies for the vast majority of crates.</p>
<p>I was wondering if it would make sense to have them specialized in <code>rust-project.json</code> since they're not included in the list of externs passed to rustc. Either through some kind of flag or matching by name.</p>



<a name="205202785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205202785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205202785">(Jul 28 2020 at 06:50)</a>:</h4>
<p>So, it’s not „them“, it’s „sysrroot crate don‘t have to be explicitly specified on he command line“. rust-analyzer deliberately lacks the concept of sysroot and requires every dependency to be explicit. So, just adding them to all te crates is how this should work</p>



<a name="205238705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205238705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205238705">(Jul 28 2020 at 14:00)</a>:</h4>
<p>Ok, and I assume that means there's no harm in leaving in, for example, <code>std</code> in a <code>no_std</code> context. Is that a safe assumption to make?</p>



<a name="205238906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205238906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205238906">(Jul 28 2020 at 14:02)</a>:</h4>
<p>Yup, that is a safe assumption</p>



<a name="205240652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205240652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205240652">(Jul 28 2020 at 14:14)</a>:</h4>
<p>Thanks!</p>



<a name="205243086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205243086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205243086">(Jul 28 2020 at 14:33)</a>:</h4>
<p>hmm, couldn't it influence import path generation?</p>



<a name="205243275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205243275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205243275">(Jul 28 2020 at 14:35)</a>:</h4>
<p>I think you can <code>extern crate std</code> in an otherwise <code>![no_std] </code> crate?<br>
`</p>



<a name="205243503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205243503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205243503">(Jul 28 2020 at 14:37)</a>:</h4>
<p>Yes, you can explicitly import any sysroot crate. <code>#![no_std]</code> just disables the implicit <code>extern crate std</code> and changes the prelude to refer to libcore instead of libstd.</p>



<a name="205243525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205243525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205243525">(Jul 28 2020 at 14:37)</a>:</h4>
<p>the import path code looks at presence of <code>#![no_std]</code> to decide which crate to prefer</p>



<a name="205243632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205243632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205243632">(Jul 28 2020 at 14:38)</a>:</h4>
<p>On embedded targets libstd literally is not present though</p>



<a name="205265835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-project.json%20and%20the%20core%20and%20alloc%20crates/near/205265835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-project.2Ejson.20and.20the.20core.20and.20alloc.20crates.html#205265835">(Jul 28 2020 at 17:30)</a>:</h4>
<p>Ok, so our assumption that we can just directly provide <code>core</code> and <code>std</code> as deps for all crates in <code>rust-project.json</code> is the correct path forward?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>